home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / comm2 / mmrsnd11.lha / MM / Rexx / MM_ResendMsg.rexx < prev    next >
OS/2 REXX Batch file  |  1996-04-28  |  8KB  |  417 lines

  1. /*
  2.  
  3.                       $VER: MM_ResendMsg 0.11  (28.04.96)
  4.  
  5.                             (C) 1996 Robert Hofmann
  6.  
  7. */
  8.  
  9. parse arg args
  10.  
  11. options cache
  12. options failat 99
  13. options results
  14.  
  15. signal on break_c
  16. signal on break_d
  17. signal on break_e
  18. signal on break_f
  19. signal on halt
  20. signal on ioerr
  21. signal on syntax
  22.  
  23. address 'MAILMANAGER'
  24.  
  25.  
  26. Main:
  27.  
  28.     call Init
  29.     call Header
  30.     call Parse_Args(strip(args))
  31.     Show
  32.  
  33.     if ~Search_Msgs() then call Quit(6, 'No msgs selected!!!')
  34.  
  35.     call Resend_Msgs
  36.  
  37. call Quit(0, 'All done.')
  38. exit
  39.  
  40.  
  41. break_c:; break_d:; break_e:; break_f:; halt:
  42.  
  43.     signal off break_c
  44.     signal off break_d
  45.     signal off break_e
  46.     signal off break_f
  47.     signal off halt
  48.  
  49.     return_code        =    5
  50.     error_line    = 0
  51.     error_msg            = 'Execution halted!!!'
  52.     rc                        = 0
  53. signal Exit
  54.  
  55.  
  56. Exit:
  57.  
  58.     select
  59.         when return_code>=40 then error = 'INTERNAL-ERROR:'
  60.         when return_code>=30 then error = 'IO-ERROR:'
  61.         when return_code>=20 then error = 'ERROR:'
  62.         when return_code>=10 then error = 'WARNING:'
  63.         when return_code>=5  then error = 'INFO:'
  64.         otherwise                                    error = ''
  65.     end
  66.  
  67.     if return_code>5 & ~system.arg.noreq then
  68.         call Request_Choice('\c\n'error'\n\n   ' error_msg '   \n', '* _OK ', '_')
  69.  
  70.   call Log()
  71.     call Log('***' strip(error error_msg) '***', '+')
  72.     call Log(,'\')
  73.  
  74.     call setclip('MM_LogPre', system.mm.logpre)
  75.  
  76. exit return_code
  77.  
  78.  
  79. Get_Arg: procedure Expose args system.
  80.  
  81.   arg keyword, mode, old
  82.  
  83.     p = find(upper(args), keyword)
  84.  
  85.     select
  86.         when mode=0    then
  87.             if p>0 then
  88.                 do
  89.                     ret        = 1
  90.                     args    = delword(args, p, 1)
  91.                 end
  92.             else ret    = old
  93.  
  94.         when mode=1 then
  95.             if p>0 then
  96.                 do
  97.                     left    = subword(args, 1, p-1)
  98.                     rest    = subword(args, p+1)
  99.  
  100.                     if left(rest, 1)='"' then    parse var rest . '"'    ret '"'    rest
  101.                     else                                            parse var rest                ret            rest
  102.  
  103.                     args    = strip(left strip(rest))
  104.                 end
  105.             else ret    = old
  106.  
  107.         when mode=2 then
  108.             do
  109.                 if left(args, 1)='"'    then    parse var args . '"'    ret '"'    args
  110.                 else                                                parse var args                ret         args
  111.  
  112.                 if strip(ret)=''            then    ret = old
  113.             end
  114.  
  115.         otherwise exit 99
  116.     end
  117.  
  118.     args    = strip(args)
  119.     ret        = strip(ret, 'b', '" ')
  120.  
  121. return ret
  122.  
  123.  
  124. Get_Version: procedure
  125.  
  126.     parse arg mode
  127.  
  128.     parse value sourceline(3-mode) with . . ver .
  129.     parse var ver tst 'ß' .
  130.  
  131.     if ~datatype(strip(tst, 'b', '/ce '), 'N') then
  132.         if ~mode then ver = Get_Version(1)
  133.         else exit 99
  134.  
  135. return ver
  136.  
  137.  
  138. Header:
  139.  
  140.     call Log(,'/')
  141.     call Log('***' system.prg.id '***', '+')
  142.     call Log(' 'system.prg.cr)
  143.     call Log()
  144.  
  145. return
  146.  
  147.  
  148. Init:
  149.  
  150.     system.                        = 0
  151.  
  152.     MM_GetTaskPri                'system.taskpri'
  153.     call                                pragma('p', system.taskpri)
  154.  
  155.     system.prg.ver        = Get_Version(0)
  156.     system.prg.name        = 'MM_ResendMsg'
  157.     system.prg.id            = system.prg.name 'v'system.prg.ver
  158.     system.prg.cr            = '(C) 1996 Robert Hofmann'
  159.     system.tmpfile        = 'T:'system.prg.name'.tmp'
  160.     system.mm.logpre     = getclip('MM_LogPre')
  161.     system.prg.logpre    = system.mm.logpre'|'
  162.     call                                setclip('MM_LogPre', system.prg.logpre)
  163.     system.cmdopts        = 'AREA/A,MSG/N,MARKED/S,NOREQ/S'
  164.  
  165.     MM_Version                    'system.mm'
  166.  
  167.     call Include_Lib('rexxsupport')
  168. return
  169.  
  170.  
  171. Include_Lib: procedure
  172.  
  173.     parse arg lib, prio
  174.     if right(upper(lib), 8)~='.LIBRARY' then lib=lib'.library'
  175.     if prio='' then prio=0
  176.  
  177.     if ~show('l', lib) then
  178.         if ~addlib(lib, prio, -30, 0) then
  179.             do
  180.                 say '*** ERROR: Could not open' lib'!!! ***'
  181.                 exit 10
  182.             end
  183. return
  184.  
  185.  
  186. IOerr:
  187.  
  188.     signal off ioerr
  189.  
  190.     return_code        = 20
  191.     error_line    = sigl
  192.     error_msg            = 'IO-error' rc 'at line' sigl '['errortext(rc)']')
  193.     rc                        = 0
  194. signal Exit
  195.  
  196.  
  197. Log: procedure Expose system.
  198.  
  199.     parse arg text, pre
  200.  
  201.     tmp        = word('PRG MM', (pre~='')+1)
  202.     text    = system.tmp.logpre || pre' 'text
  203.  
  204.     MM_WriteLog 'text' '2'
  205. return
  206.  
  207.  
  208. Parse_Args: procedure Expose system.
  209.  
  210.     parse arg args
  211.  
  212.     tpl        = system.cmdopts',?/S,'
  213.     args    = translate(args, '  ', '9'x'=')
  214.  
  215.     pk        = pos('/K', tpl)
  216.     ps        = pos('/S', tpl)
  217.  
  218.     select
  219.         when pk=0    & ps=0    then    p    = 0
  220.         when pk=0 & ps>0    then  p    = ps
  221.         when ps=0 & pk>0    then    p    = pk
  222.         otherwise                                p    = min(pk, ps)
  223.     end
  224.  
  225.     p            = lastpos(',', left(tpl, p))
  226.     tpl        = substr(tpl, p+1) || left(tpl, max(p-1, 0))
  227.  
  228.     do while tpl~=''
  229.         parse var tpl template ',' tpl
  230.         parse var template keyword '/' .
  231.  
  232.         bool    = pos('/S',    template)>0
  233.         key        = pos('/K', template)>0
  234.         must    = pos('/A', template)>0
  235.         num        = pos('/N', template)>0
  236.  
  237.         select
  238.             when must then        system.arg.keyword    = '0'x
  239.             when bool    then        system.arg.keyword    = 0
  240.             when num    then        system.arg.keyword    = 0
  241.  
  242.             otherwise                    system.arg.keyword    = ''
  243.         end
  244.  
  245.         if bool | key    then    mode    = ~bool
  246.         else                                mode    = 2
  247.  
  248.         system.arg.keyword    = Get_Arg(keyword, mode, system.arg.keyword)
  249.  
  250.         if keyword='?' & system.arg.keyword=1 then leave
  251.  
  252.         if must & system.arg.keyword='0'x then
  253.             do
  254.                 tmp    = template 'missing!!!'
  255.  
  256.                 say
  257.                 say ' ***' tmp '***'
  258.  
  259.                 signal Usage
  260.             end
  261.  
  262.         if num & ~datatype(system.arg.keyword, 'N') then
  263.             if ~must & system.arg.keyword='' then    system.arg.keyword    = 0
  264.             else
  265.                 do
  266.                     tmp    = 'Numeric value expected for' template', but is "'system.arg.keyword'"!!!'
  267.  
  268.                     say
  269.                     say ' ***' tmp '***'
  270.  
  271.                     signal Usage
  272.                 end
  273.     end
  274.  
  275.     tmp    = '?'; if system.arg.tmp then signal Usage
  276.  
  277.     if args~='' then call Quit(10, 'Unknown option(s):' args)
  278.  
  279.     MM_GetAreaInfo system.arg.area 'tmp'
  280.     if RC~=0    then call Quit(11, 'Area "'system.arg.area'" does not exist!')
  281.  
  282.     if system.arg.marked & system.arg.msg>0                then call Quit(12, 'You must not use MARKED/S together with MSG/N')
  283.     if system.arg.msg=0 & ~system.arg.marked            then call Quit(13, 'Too few arguments!!!')
  284.     if system.arg.marked & system.mm.release<423    then call Quit(14, 'Sorry, you need MM >= v1.2.423 to use MARKED/S!')
  285.  
  286. return
  287.  
  288.  
  289. Quit:
  290.  
  291.     parse arg return_code, error_msg
  292.  
  293.     error_line    = 0
  294.     rc                        = 0
  295. signal Exit
  296.  
  297.  
  298. Replace: procedure
  299.  
  300.     parse arg string,new,old
  301.  
  302.     do while index(string, old) ~= 0
  303.         interpret "parse var string l '"old"' r"
  304.         string = l || new || r
  305.     end
  306.  
  307. return string
  308.  
  309.  
  310. Request_Choice: procedure Expose system.
  311.  
  312.     parse arg text, buttons, ret_vals
  313.  
  314.     title    = system.prg.name'-Requester'
  315.     text    = translate(Replace(text, '0A'x, '\n'), '1b'x, '\')
  316.  
  317.     if length(text)<40 then text = center(text, 40)
  318.  
  319.     MM_Requester title 'text' 'buttons'
  320.  
  321.     if rc=0 then rc=words(ret_vals)
  322.  
  323. return compress(word(ret_vals, rc), '_')
  324.  
  325.  
  326. Resend_Msgs: procedure Expose system.
  327.  
  328.     if system.arg.msg=0    then
  329.         if ~Request_Choice('\c\n    Resend selected msg(s)?    \n', '* _YES | _NO ', '1 0') then
  330.             call Quit(5, 'Aborted by user!')
  331.  
  332.     do n=0 to system.msgs.count-1
  333.         MM_ReadMsg system.arg.area system.msgs.n 'msg'
  334.         if RC>0 then
  335.             do
  336.                 call Warn_Req('Msg #'system.msgs.n 'does not exist!')
  337.                 iterate
  338.             end
  339.  
  340.         tmp                = msg.flags
  341.         msg.flags    = '!DEL !MARK !SENT'
  342.  
  343.         do while tmp~=''
  344.             parse var tmp check tmp
  345.  
  346.             if find('DEL IMP MARK SENT', check)=0 then msg.flags    = msg.flags check
  347.         end
  348.  
  349.         new.    = 0
  350.  
  351.         do m=0 to msg.head.count-1
  352.             parse value strip(msg.head.n, 'b', '010D'x' ') with check .
  353.  
  354.             if find('CHRS: MSGID: PID: TID:', check)=0    then MM_AddToStem 'new' 'msg.head.'n
  355.         end
  356.  
  357.         msg.file        = system.tmpfile
  358.  
  359.         MM_WriteStem    system.tmpfile    'new'
  360.         MM_WriteStem    system.tmpfile    'msg.text'
  361.  
  362.         MM_EditMsg        system.arg.area    system.msgs.n 'msg'
  363.         if RC>0 then     call Warn_Req('Error' RC 'while trying to edit msg #'system.msgs.n'!')
  364.         else                    call Log('Resended' system.arg.area', msg #'system.msgs.n'.')
  365.     end
  366.  
  367. return
  368.  
  369.  
  370. Search_Msgs: procedure Expose system.
  371.  
  372.     if system.arg.msg>0 then MM_AddToStem 'system.msgs' 'system.arg.msg'
  373.     else
  374.         do
  375.             call Log('Searching for marked msgs...')
  376.  
  377.             MM_SearchMsgs system.arg.area 'system.msgs' '#?' '#?' '#?' 'MARK'
  378.         end
  379.  
  380. return system.msgs.count>0
  381.  
  382.  
  383. Syntax:
  384.  
  385.     signal off syntax
  386.  
  387.     return_code        = 40
  388.     error_line    = sigl
  389.     error_msg            = 'Syntax-error' rc 'at line' sigl '['errortext(rc)']'
  390.     rc                        = 0
  391. signal Exit
  392.  
  393.  
  394. Usage:
  395.  
  396.     rx.            = ''
  397.     rx.0.0    = '[rx] '
  398.     rx.0.1    = '[.rexx]'
  399.     m                =    pos('/e', system.prg.ver)>0
  400.     tmp            = rx.m.0 || system.prg.name || rx.m.1
  401.  
  402.     say
  403.     say 'Usage:' tmp system.cmdopts
  404.     say
  405. call Quit(5, 'Usage requested.')
  406.  
  407.  
  408. Warn_Req: procedure Expose system.
  409.  
  410.     parse arg text
  411.  
  412.     if ~system.arg.noreq then call Request_Choice('\c\n'system.warn'\n\n'text'\n', '*  _OK  ', '_')
  413.     call Log(system.warn text)
  414.  
  415. return
  416.  
  417.